package com.qianxx.component.activity.progress.arc_progress;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

import com.qianxx.component.R;
import com.qianxx.component.activity.base.BaseActivity;
import com.qianxx.viewlibrary.progress.arc.ArcProgress;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ArcProgressActivity extends BaseActivity {

    @BindView(R.id.progress1)
    ArcProgress progress1;
    @BindView(R.id.progress2)
    ArcProgress progress2;
    @BindView(R.id.progress3)
    ArcProgress progress3;
    @BindView(R.id.progress4)
    ArcProgress progress4;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_arc_progress);
        ButterKnife.bind(this);

        progress1.startAnimation();
        progress2.setFlatBottom(true);
        progress2.startAnimation();
        progress4.setFlatBottom(true);

        new Thread(new Runnable() {

            @Override
            public void run() {
                for (int i = 1; i <= 100; i++) {
                    try {
                        handler.sendEmptyMessage(i);
                        Thread.sleep(25);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }).start();
    }

    Handler handler = new Handler() {
        @Override
        public void dispatchMessage(Message msg) {
            super.dispatchMessage(msg);
            progress3.setProgress(msg.what);
            progress4.setProgress(msg.what);
        }
    };

    @Override
    public String setTitle() {
        return "ArcProgress";
    }
}
